package cn.kgc.tafang.util;

import cn.kgc.tafang.dao.GameDao;
import cn.kgc.tafang.dao.Init;
import cn.kgc.tafang.dao.UserDao;
import cn.kgc.tafang.dao.impl.GameDaoImpl;
import cn.kgc.tafang.dao.impl.UserDaoImpl;
import cn.kgc.tafang.entity.Hero;
import cn.kgc.tafang.entity.User;
import cn.kgc.tafang.service.UserOpera;

import java.io.File;
import java.util.Collection;
import java.util.Map;
import java.util.Scanner;

public class Menu extends Thread{
    public static Map<String,Hero> heroMap= Init.heroMap;
    public static Collection<Hero> heros=heroMap.values();
    public Map<String,User> userss= Init.users;
    Scanner sc=new Scanner(System.in);
    UserDao users=new UserDaoImpl();
    GameDao gameDao=new GameDaoImpl();
    static User user=null;
    File file=new File("aaa.txt");
    public void a(){
        do {
            System.out.println("1、注册");
            System.out.println("2、登陆");
            System.out.println("请选择:");
            int choice=sc.nextInt();
            User user = null;
            switch (choice) {
                case 1:
                    System.out.println("请输入用户名:");
                    String name = sc.next();
                    System.out.println("请输入密码:");
                    String pwd = sc.next();
                    user = new User(name, pwd);
                    users.addUser(user);
                    break;
                case 2:
                    System.out.println("请输入用户名:");
                    name = sc.next();
                    System.out.println("请输入密码:");
                    pwd = sc.next();
                    user=new User(name,pwd);
                    user=users.checkLogin(user);
                    if (user!=null) {
                        System.out.println("登陆成功!");
                        System.out.println("欢迎进入塔防世界!");
                        System.out.println("----------------------------------------------");
                        if (file.exists()){
                            userss= (Map<String,User>) UserOpera.unSeria(file);
                        }
                        if(user.getHero().getName()==null||user.getHero().getName().equals("")) {
                            System.out.println("请注册属于你的英雄名:");
                            String names = sc.next();
                            user.getHero().setName(names);
                            //序列化
                            userss.put(user.getName(),user);
                            UserOpera.Seria(userss,file);
                        }
                        System.out.println("召唤师<"+user.getHero().getName()+">，欢迎来到塔防大陆!!");



                        do {
                            System.out.println("1.开始游戏");
                            System.out.println("2.商城");
                            System.out.println("3.英雄信息");
                            System.out.println("4.仓库");
                            System.out.println("5.看广告得金币");
                            System.out.println("6.点卷充值");
                            System.out.println("7.退出");
                            System.out.println("请选择:");

                            int choices = sc.nextInt();
                            switch (choices) {
                                case 1:
                                   gameDao.playGame(user);
                                    break;
                                case 2:
                                    System.out.println("1、买装备");
                                    System.out.println("2、买技能");
                                    System.out.println("3、卖装备");
                                    System.out.println("4、卖技能");
                                    System.out.println("请选择:");
                                    choices = sc.nextInt();
                                    gameDao.Shangcheng(choices,user);
                                    break;
                                case 3:
                                    gameDao.showHero(user);
                                    break;
                                case 4:
                                    System.out.println("1、更改装备");
                                    System.out.println("2、更改技能");
                                    System.out.println("请选择:");
                                    choice = sc.nextInt();
                                    gameDao.choiceZhuangB(choice,user);
                                    break;
                                case 5:
                                    gameDao.getMoney(user);
                                    break;
                                case 6:
                                    System.out.println("60--100    送200金币");
                                    System.out.println("100-300    送300金币");
                                    System.out.println("300以上    送500金币");
                                    System.out.println("召唤师请输入你要充值的点卷数:");
                                    choice = sc.nextInt();
                                    gameDao.getDianJuan(choice,user);
                                    break;
                                case 7:
                                    System.out.println("退出游戏,欢迎下次再来!");
                                    return;
                            }
                        }while (true);
                    }else {
                        System.out.println("用户名或密码错误，请重新登陆!");
                    }
            }
        }while (true);
    }
}
